﻿
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Cl.Model.DataBaseEntityDtos.User.User
{
    public class UserOutDto
    {
        public UserOutDto()
        {
        }
        public UserOutDto(Entity.DataBaseEntity.User.User user)
        {
            Id = user.Id;
            UserName = user.UserName;
            Account = user.Account;

            DepartmentId = user.DepartmentId;
            DepartmentName = user?.Department?.Name ?? "";

            RoleIds = user.UserRoles.Select(x => x.Role.Id).ToList();
            RoleName = string.Join(',', user.UserRoles.Select(x => x.Role.Name).ToList());

            IsEnable = user.IsEnable;
            CreateId = user.CreateId;
            if (user.CreateUser != null)
                CreateName = user.CreateUser.UserName;
            CreateTime = user.CreateTime;

            UpdateId = user.UpdateId;
            UpdateTime = user.UpdateTime;

            UpdateName = user?.UpdateUser?.UserName ?? "";



            //var a = AutoMapHelper.MapTo<Entity.DataBaseEntity.User.User, UserOutDto>(user);
        }

        public int Id { get; set; }

        public string UserName { get; set; } = string.Empty;
        public string Account { get; set; } = string.Empty;


        public int? DepartmentId { get; set; }
        public string DepartmentName { get; set; }

        public List<int> RoleIds { get; set; }
        public string RoleName { get; set; }



        public int IsEnable { get; set; } = 1;

        public int CreateId { get; set; }
        public string CreateName { get; set; }

        public DateTime CreateTime { get; set; }

        public int? UpdateId { get; set; }
        public string UpdateName { get; set; }
        public DateTime? UpdateTime { get; set; }
    }
}
